import {Service, action} from "adajs";
import LgbadList from "./../lgbad";

class CourseService extends Service {
    defaultData() {
        return {
            list: []
        }
    }

    onupdate(current, {list}) {
        current.list = list.map(item => {
            return Object.assign({}, item, {
                opened: false,
                list: {
                    url: "/api/lgb/app/lgb/branchcheckin/getByDept",
                    type: LgbadList,
                    parameter: {
                        id: item.id
                    }
                }
            });
        });
        if (current.list[0]) {
            current.list[0].opened = true;
        }
    }

    @action("open")
    open(current, item) {
        current.list.forEach(_item => {
            if (_item.id === item.id) {
                _item.opened = true;
            } else {
                _item.opened = false;
            }
        });
    }
}

export default CourseService;